package com.newlink.building.login.mvp.presenter

import com.newlink.building.login.mvp.contract.Module_Login_InputNewPwdContract
import com.newlink.building.login.mvp.model.Module_Login_InputNewPwdModel
import com.newlink.building.common_base.base.BasePresenter
import com.newlink.building.common_base.ext.ss
import com.newlink.building.common_base.http.tools.Base_TokenUpdateUtils
import com.newlink.building.common_base.model.bean.NewKitPasswordBean
import com.newlink.building.common_base.model.bean.NewPasswordBean
import com.newlink.building.common_base.utils.logDebug

/**
 * @Author: Jake
 * @Date: 2023-04-06
 * @Description:
 */
class Module_Login_InputNewPwdPresenter : BasePresenter<Module_Login_InputNewPwdContract.Model, Module_Login_InputNewPwdContract.View>(),
    Module_Login_InputNewPwdContract.Presenter {

    override fun createModel(): Module_Login_InputNewPwdContract.Model = Module_Login_InputNewPwdModel()
    override fun sendNewPwd(bean: NewPasswordBean) {
        mModel?.sendNewPwd(bean)?.ss(mModel, mView) { response ->
            logDebug<Module_Login_InputNewPwdPresenter>("密码设置 response - $response")
            response?.let {
                if (it.code == 200) {
                    mView?.setNewPwdSuccess()
                } else {
                    mView?.setNewPwdFailed(it?.data.orEmpty())
                }
            }

        }
    }

    override fun sendNewKitPwd(token: String, bean: NewKitPasswordBean) {
        mModel?.sendNewKitPwd(token, bean)?.ss(mModel, mView) { response ->
            logDebug<Module_Login_InputEmailPresenter>("密码设置 response - $response")
            response?.let {
                if (it.code == 200) {
                    mView?.setNewPwdSuccess()
                } else {
                    mView?.setNewPwdFailed(it?.data.orEmpty())
                }
            }

        }
    }

    private fun refreshToken(userId: Long, token: String, pwd: String) {
        Base_TokenUpdateUtils().update(0, token) { }
    }
}